package com.bqtv.sport.ui.home.fragment

import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.viewbinding.ViewBinding
import com.bqtv.sport.R
import com.bqtv.sport.adapter.LiveChatAdapter
import com.bqtv.sport.app.AppActivity
import com.bqtv.sport.app.AppFragment
import com.bqtv.sport.databinding.FragmentLiveChatBinding


class LiveChatFragment : AppFragment<FragmentLiveChatBinding, AppActivity<ViewBinding>>() {
    private var inputChatMsgDialog: InputChatMsgDialogFragment? = null
    private var mChatLayoutManager: LinearLayoutManager? = null
    private var mChatAdapter: LiveChatAdapter? = null
    companion object {
        private const val INTENT_KEY_TYPE = "type"
        fun newInstance(): LiveChatFragment {
            val fragment = LiveChatFragment()
            val bundle = Bundle()
            fragment.arguments = bundle
            return fragment
        }

        fun newInstance(type: String?): LiveChatFragment {
            val fragment = LiveChatFragment()
            val bundle = Bundle()
            bundle.putString(INTENT_KEY_TYPE, type)
            fragment.arguments = bundle
            return fragment
        }
    }

    override fun getViewBinding() = FragmentLiveChatBinding.inflate(layoutInflater)

    override fun initView() {

    }

    override fun initData() {
        mChatAdapter= LiveChatAdapter()
        mChatLayoutManager = LinearLayoutManager(getContext())
        binding.rvChat.setLayoutManager(mChatLayoutManager)
        binding.rvChat.setAdapter(mChatAdapter)
        initListener()
    }

    private fun initListener() {
        binding.rlChat.setOnClickListener(this)
        binding.ivCoin.setOnClickListener(this)
        binding.ivMsg.setOnClickListener(this)
        binding.ivSend.setOnClickListener(this)
    }

    override fun onClick(view: View) {
        super.onClick(view)
        when (view.id) {
            R.id.rl_chat -> {
                showInputTextMsgDialog(InputChatMsgDialogFragment.STATE_SOFT_INPUT)
            }
            R.id.iv_coin -> {

            }
            R.id.iv_msg -> {

            }
            R.id.iv_send -> {
                showInputTextMsgDialog(InputChatMsgDialogFragment.STATE_SOFT_INPUT)
            }
        }
    }

    private fun showInputTextMsgDialog(state: Int) {
        inputChatMsgDialog = InputChatMsgDialogFragment()
        val bundle = Bundle()
        bundle.putInt("state", state)
//        if (mNobelBean != null) {
//            bundle.putSerializable("bean", mNobelBean)
//        }
//        if ((getActivity() as LiveDetailActivity).mLiveRoomBean != null) {
//            bundle.putSerializable(
//                "user",
//                (getActivity() as LiveDetailActivity).mLiveRoomBean.getUserData()
//            )
//        }
//        bundle.putSerializable("danmu", mDanmuList as Serializable?)
        inputChatMsgDialog?.setArguments(bundle)
        inputChatMsgDialog?.show(getChildFragmentManager(), "InputChatMsgDialogFragment")
    }
}

